home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Mac Format 1994 October
/
Macformat17.cdr
/
Shareware City
/
Developers
/
Kamprath's CDEF Pack ƒ
/
CDEF Sampler Program ƒ
/
samplerControls.c
< prev
next >
Wrap
C/C++ Source or Header
|
1994-06-12
|
6KB
|
279 lines
#include "samplerControls.h"
#include "number_picker.h"
ControlHandle rocketCntl, timeButtonCntl, timeCntl, dateCntl, numberCntl;
ControlHandle squarePlain, squareBold, squareLarge;
DateTimeRec *theTime;
extern WindowPtr samplerWindow;
void SetUpWindowCntls( void )
{
Rect ctrlRect;
SetRect(&ctrlRect, 5,15,37,47);
rocketCntl = NewControl( samplerWindow, &ctrlRect, "\p",
TRUE, 0, 0, 1, 1000*16 + 0, 0 );
SetRect(&ctrlRect, 5,55,37,87);
timeButtonCntl = NewControl( samplerWindow, &ctrlRect, "\p",
TRUE, 0, 0, 1, 1000*16 + 1, 0 );
theTime = (DateTimeRec *)NewPtrClear(sizeof(DateTimeRec));
GetTime( theTime );
SetRect(&ctrlRect, 15,95,180,115);
timeCntl = NewControl( samplerWindow, &ctrlRect, "\pTime Control", TRUE,
0, 0, 128, 16*1001 + kTimeVariation,
(long)(theTime));
SetRect(&ctrlRect, 15,120,180,140);
dateCntl = NewControl( samplerWindow, &ctrlRect, "\pTime Control", TRUE,
0, 0, 128, 16*1001 + kDateVariation,
(long)(theTime));
SetRect(&ctrlRect, 5,145,155,165);
numberCntl = NewControl( samplerWindow, &ctrlRect, "\pNumber Control:", TRUE,
0, 0, 5000, 16*1002 + 0, 0);
SetRect(&ctrlRect, 190,15,340,35);
squarePlain = NewControl( samplerWindow, &ctrlRect, "\pTimes Plain", TRUE,
0, 12, times, 16*500, 0);
SetRect(&ctrlRect, 190,40,340,65);
squareBold = NewControl( samplerWindow, &ctrlRect, "\pSystem Bold", TRUE,
bold, 12, 0, 16*501, 0);
SetRect(&ctrlRect, 190,70,340,100);
squareLarge = NewControl( samplerWindow, &ctrlRect, "\pCourier Large", TRUE,
0, 18, courier, 16*502, 0);
}
pascal void NumCDEFProc(ControlHandle theControl, short theCode)
{
static long lastTicks = 0;
if (theCode == 0)
return ;
if (TickCount() < lastTicks+10)
return;
switch (theCode)
{
case kNPArrowButtonUp:
SetCtlValue( theControl, GetCtlValue(theControl)+1);
break;
case kNPArrowButtonDown:
SetCtlValue( theControl, GetCtlValue(theControl)-1);
break;
}
lastTicks = TickCount();
}
/*
* Time & Date CEF Handler routines
*
*/
long ticks, curWait;
void HandleTimeCDEFClick(Point where)
{
short thePart, trackPart;
ControlHandle ch;
ticks = TickCount();
curWait = 60;
trackPart = TrackControl( timeCntl, where, TimeCDEFAction);
if (trackPart)
{
HandleTimeCDEFPart( timeCntl, trackPart);
}
}
void HandleDateCDEFClick(Point where)
{
short thePart, trackPart;
ControlHandle ch;
ticks = TickCount();
curWait = 60;
trackPart = TrackControl( dateCntl, where, DateCDEFAction);
if (trackPart)
{
HandleDateCDEFPart( dateCntl, trackPart);
}
}
pascal void TimeCDEFAction( ControlHandle ch, short part)
{
if (TickCount() >= ticks + curWait)
{
HandleTimeCDEFPart( ch, part);
ticks = TickCount();
curWait = 15;
}
}
pascal void DateCDEFAction( ControlHandle ch, short part)
{
if (TickCount() >= ticks + curWait)
{
HandleDateCDEFPart( ch, part);
ticks = TickCount();
curWait = 15;
}
}
void HandleTimeCDEFPart( ControlHandle ch, short part)
{
DateTimeRec *theTime;
unsigned long timeNum;
switch (part)
{
case kHourItem:
SetCtlValue( ch, kHourItem);
break;
case kMinItem:
SetCtlValue( ch, kMinItem);
break;
case kAMPMItem:
SetCtlValue( ch, kAMPMItem);
break;
case kArrowButtonUp:
theTime = (DateTimeRec *)GetCRefCon(ch);
switch (GetCtlValue(ch))
{
case kHourItem:
if (theTime->hour < 23)
{
(theTime->hour)++;
}
break;
case kMinItem:
if (theTime->minute < 59)
{
(theTime->minute)++;
}
break;
case kAMPMItem:
if ( (theTime->hour + 12) <= 23)
{
(theTime->hour) += 12;
}
break;
}
Draw1Control( ch );
break;
case kArrowButtonDown:
theTime = (DateTimeRec *)GetCRefCon(ch);
switch (GetCtlValue(ch))
{
case kHourItem:
if (theTime->hour > 0)
{
(theTime->hour)--;
}
break;
case kMinItem:
if (theTime->minute > 0)
{
(theTime->minute)--;
}
break;
case kAMPMItem:
if ( (theTime->hour - 12) >= 0)
{
(theTime->hour) -= 12;
}
break;
}
Draw1Control( ch );
break;
default:
SetCtlValue( ch, 0);
break;
}
}
void HandleDateCDEFPart( ControlHandle ch, short part)
{
DateTimeRec *theTime;
unsigned long timeNum;
switch (part)
{
case kMonthItem:
SetCtlValue( ch, kMonthItem);
break;
case kDateItem:
SetCtlValue( ch, kDateItem);
break;
case kYearItem:
SetCtlValue( ch, kYearItem);
break;
case kDayOfWeekItem:
SetCtlValue( ch, kDayOfWeekItem);
break;
case kArrowButtonUp:
theTime = (DateTimeRec *)GetCRefCon(ch);
switch (GetCtlValue(ch))
{
case kMonthItem:
if (theTime->month < 12)
{
(theTime->month)++;
}
break;
case kDateItem:
case kDayOfWeekItem:
(theTime->day)++;
Date2Secs(theTime, &timeNum);
Secs2Date(timeNum, theTime);
break;
case kYearItem:
if (theTime->year < 2040)
{
(theTime->year)++;
}
break;
}
Draw1Control( ch );
break;
case kArrowButtonDown:
theTime = (DateTimeRec *)GetCRefCon(ch);
switch (GetCtlValue(ch))
{
case kMonthItem:
if (theTime->month > 1)
{
(theTime->month)--;
}
break;
case kDateItem:
case kDayOfWeekItem:
(theTime->day)--;
Date2Secs(theTime, &timeNum);
Secs2Date(timeNum, theTime);
break;
case kYearItem:
if (theTime->year > 1904)
{
(theTime->year)--;
}
break;
}
Draw1Control( ch );
break;
default:
SetCtlValue( ch, 0);
break;
}
}